import Util.HttpUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static Util.Rules.disable_Indicator;
import static Util.Rules.indicator_Matching_Rules;
import static Util.UrlCollect.*;

/*
  输出缺失的指标对象
 */
public class QueryEmptyIndicatorObjects {
    public static void main(String[] args) throws IOException {

        HttpUtil http = new HttpUtil();
        Map<String, String> paramsMap = new HashMap<>();
        HashSet<String> nullSet =new HashSet<>();

        String params1 = "{\"pageNum\": 1, \"pageCount\": 2000}";

        JSONObject jsonObject1 = http.doBodyPost(GET_ALL_TEMPLATES_URL, params1);
        JSONArray array = jsonObject1.getJSONObject("data").getJSONArray("data");
        for (Object o1 : array) {
            JSONObject json4 = (JSONObject) o1;
            String m_name = json4.getString("name");
            if (json4.getIntValue("id") >= 88) {
                continue;
            }
            System.out.println("=======================" + m_name + "=======================");
            paramsMap.put("id", json4.get("id").toString());

            String res = http.doParamsPost(OBTAIN_OUTLINE_URL, paramsMap);
            JSONObject object = JSONObject.parseObject(res);
            for (Object json : object.getJSONArray("data")) {
                JSONObject object1 = (JSONObject) json;
                int key = object1.getIntValue("key");
                String title = object1.getString("title");
                String pa = "{\"id\":" + key + "}";
                JSONObject s = null;
                try {
                    s = http.doBodyPost(GET_DETAILS_URL, pa);
                    JSONArray s1 = s.getJSONArray("data");
                    for (Object json1 : s1) {
                        JSONObject json2 = (JSONObject) json1;
                        JSONArray data = json2.getJSONArray("data");
                        if (data != null) {
                            for (Object s2 : data) {
                                JSONObject s21 = (JSONObject) s2;
                                String titleFootnote = removeParentheses(json2.getString("titleFootnote"));
//                                if (s21.getString("type").equals("UNKNOWN_INDICATOR_OBJECT")&& !disable_Indicator(titleFootnote)) {
//                                    System.out.println(m_name+" "+title + "  " + titleFootnote);
//                                }
//                                if (s21.getString("type").equals("UNKNOWN_INDICATOR_OBJECT")&&!titleFootnote.contains("定义")) {
//                                    System.out.println(titleFootnote);
//                                }
                            }
                        }
                    }

                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        nullSet.forEach(System.out::println);
    }
    public static String removeParentheses(String input) {
        Pattern pattern = Pattern.compile("\\{([^{}])*\\}");
        Matcher matcher = pattern.matcher(input);
        return matcher.replaceAll("").trim();
    }

}
